<template>
	<view class="account">
		<view class="list-block">
			<view class="box-flex-between list-row" @click="toUpdateAccount">
				<view>登录账号</view>
				<view>
					<text class="text">{{userInfo.uname}}</text>
					<uni-icons type="forward"></uni-icons>
				</view>
			</view>
			<view class="box-flex-between list-row" @click="toUpdatePhone">
				<view>手机号</view>
				<view>
					<text class="text" v-if="userInfo.phone">{{userInfo.phone}}</text>
					<uni-icons type="forward"></uni-icons>
				</view>
			</view>
			<!-- #ifdef APP-PLUS || H5 -->
			<view class="box-flex-between list-row" @click="toUpdatePwd">
				<view>修改登录密码</view>
				<uni-icons type="forward" color="$$uni-base-color"></uni-icons>
			</view>
			<!-- #endif -->
		</view>
		<view class="list-block">
			<view class="box-flex-between list-row" @click="dialogShow = true">
				<view>注销账号</view>
				<uni-icons type="forward"></uni-icons>
			</view>
		</view>
		<cu-dialog :show="dialogShow" message="您确定要注销账号" @confirm="removeAccount" @cancel="dialogShow = false">
		</cu-dialog>
		<cu-dialog :show="successDialogShow" :message="successMessage" @confirm="toIndex" :showCancelBtn="false">
		</cu-dialog>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: {},
				dialogShow: false,
				successDialogShow: false,
				successMessage: ''
			};
		},
		onLoad() {
			this.userInfo = getApp().globalData.userInfo
		},
		methods: {
			toUpdateAccount() {
				uni.navigateTo({
					url: '/pagesMy/setting/account/updateAccount'
				})
			},
			toUpdatePhone() {
				uni.navigateTo({
					url: '/pagesMy/setting/account/updatePhone'
				})
			},
			toUpdatePwd() {
				uni.navigateTo({
					url: '/pagesMy/setting/account/updatePwd'
				})
			},
			removeAccount() {
				this.dialogShow = false;
				this.$api.post('/appUser/removeUser').then(res => {
					this.$util.removeLoginToken();
					getApp().globalData.userInfo = null;
					this.successMessage = res.message;
					this.successDialogShow = true
				})
			},
			toIndex() {
				this.successDialogShow = false
				uni.reLaunch({
					url: '/pages/index/index'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.account {
		.text {
			color: $uni-base-color;
		}
	}
</style>
